<?php

declare(strict_types=1);


namespace app\controller\index;

use app\result\SettingResult;

/**
 * 协议
 */
class Agreement
{
    /**
     * 注册协议
     * @deprecated
     */
    public function register()
    {
        $settingResult = new SettingResult();
        $setting = $settingResult->get("register_agreement");
        $title = $setting['title'] ?? '注册协议';
        $content = $setting['value'] ?? '';
        $content = htmlspecialchars_decode($content);
        return view('index/agreement', compact('title', 'content'));
    }

    /**
     * 隐私政策
     * @deprecated
     */
    public function privacy()
    {
        $settingResult = new SettingResult();
        $setting = $settingResult->get("privacy_agreement");
        $title = $setting['title'] ?? '隐私政策';
        $content = $setting['value'] ?? '';
        $content = htmlspecialchars_decode($content);
        return view('index/agreement', compact('title', 'content'));
    }

    /**
     * 关于我们
     * @deprecated
     */
    public function about()
    {
        $settingResult = new SettingResult();
        $setting = $settingResult->get("about");
        $title = $setting['title'] ?? '关于我们';
        $content = $setting['value'] ?? '我们是一个好用的记账软件';
        $content = htmlspecialchars_decode($content);
        return view('index/agreement', compact('title', 'content'));
    }

    //文章类型详情
    public function info()
    {
        $key = input('key', '', 'trim');
        if (!$key) {
            data_return('参数错误', 1);
        }
        if ($key == 'service') {
            $key = 'about';
        } elseif ($key == 'register') {
            $key = 'register_agreement';
        } elseif ($key == 'privacy') {
            $key = 'privacy_agreement';
        }
        $settingResult = new SettingResult();
        $setting = $settingResult->get($key);
        if ($setting) {
            $setting['value'] = htmlspecialchars_decode($setting['value']);
        }
        data_return('success', 0, [
            'info' => $setting
        ]);
    }
}
